package com.my.lab.adapter;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.sax.StartElementListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.my.lab.R;
import com.my.lab.util.MyAdapter;
import com.my.lab.util.ToolsUtil;

public class AppAdapter  extends MyAdapter{

    public AppAdapter(Context context, List<HashMap<String, Object>> listData) {
        super(context, listData);
    }
    
    class ViewHolder{
        ImageView app_icon;
        TextView app_name,app_version,app_size;
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final HashMap<String, Object> item = listData.get(position);
        View v = showLoadingItem(item);
        if(v != null)
            return v;
        v = convertView ;
        ViewHolder vh = null ;
        if(v == null || v.getTag() == null) {
            v = lInflater.inflate(R.layout.app_item_layout, null);
            vh = new ViewHolder();
            vh.app_icon = (ImageView) v.findViewById(R.item_id.iv_icon);
            vh.app_name = (TextView) v.findViewById(R.item_id.tv_name);
            vh.app_version = (TextView) v.findViewById(R.item_id.tv_version);
            vh.app_size = (TextView) v.findViewById(R.item_id.tv_size);
            v.setTag(vh);
        } else {
           vh =(ViewHolder) v.getTag();
        }
        if(item.containsKey("appIcon"))
            vh.app_icon.setImageDrawable((Drawable)item.get("appIcon"));
        if(item.containsKey("appName"))
            vh.app_name.setText((String)item.get("appName"));
        if(item.containsKey("versionName"))
            vh.app_version.setText("版本:"+(String)item.get("versionName"));
        if(item.containsKey("appSize"))
            vh.app_size.setText((String)item.get("appSize"));
        v.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {   
                ToolsUtil.showInstalledAppDetails(context, (String)item.get("packageName"));
            }
        });
        return v;
    }

}
